GBML manual / Lists

list_sum

Adds up all the numbers target holds: list_sum(gold) of 5, 10 and 20 is 35. Use it for the total gold, damage or points.

Works differently on Game Boy - A total on the Game Boy goes round past 32,767 (a total of decimals past 1,023.97), where the Game Boy Advance goes on to billions.

Works differently on Game Boy Color - A total on the Game Boy Color goes round past 32,767 (a total of decimals past 1,023.97), where the Game Boy Advance goes on to billions.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

list_sum(target) -> element

Arguments

NameType
targetlist

Returns

element

Description

Adds up all the numbers in target, a list. list_sum(scores) of 7, 3 and 9 is 19. Use it for the total gold, damage or points.

Example

/// @type {list<int>}
var scores = [7, 3, 9];
var answer = list_sum(scores);   // 19

The small print

Cost

One pass over the items.

On the GBA

One pass adding every item. Whole numbers add up as whole numbers (and go wrong past about 2.1 billion); decimals add up as decimals and wrap round past 524,287, like every real sum in GBML. Whole numbers and decimals only; text, yes-or-no values, structs and references are refused when the project is checked. An empty one gives back 0.

See also: list_maxlist_minlist_sort_byarray_sumlist_lengthListsData containers